home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / hardware / galer21.lha / GALer21 / Source / GALer / Sub.c < prev   
C/C++ Source or Header  |  1996-04-05  |  68KB  |  2,353 lines

  1. /******************************************************************************
  2. ** Sub.c
  3. *******************************************************************************
  4. **
  5. ** description:
  6. **
  7. ** This file contains some subroutines for GALer.
  8. **
  9. ******************************************************************************/
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16. /********************************* includes **********************************/
  17.  
  18. #include <libraries/mui.h>
  19.  
  20. #include <dos/dostags.h>
  21. #include <exec/types.h>
  22. #include <exec/memory.h>
  23. #include <devices/timer.h>
  24. #include <libraries/dos.h>
  25. #include <libraries/dosextens.h>
  26. #include <libraries/reqtools.h>
  27. #include <libraries/locale.h>
  28. #include <intuition/intuition.h>
  29.  
  30. #include <proto/locale.h>
  31. #include <proto/reqtools.h>
  32. #include <proto/intuition.h>
  33. #include <proto/exec.h>
  34. #include <proto/dos.h>
  35. #include <proto/muimaster.h>
  36.  
  37. #include <stdio.h>
  38. #include <string.h>
  39. #include <ctype.h>
  40.  
  41. #include "GALer.h"
  42. #include "Localize.h"
  43.  
  44.  
  45.  
  46.  
  47.  
  48. /********************************** defines **********************************/
  49.  
  50. #define YES_GADID         1
  51. #define NO_GADID          2
  52. #define OK_GADID         10
  53. #define CONT_GADID       11
  54. #define CANCEL_GADID     12
  55.  
  56.  
  57. #define MAKEJED_ID        1             /* gadget IDs for assembler options */
  58. #define MAKEFUSE_ID       2
  59. #define MAKECHIP_ID       3
  60. #define MAKEPIN_ID        4
  61. #define AUTOSAVE_ID       5
  62. #define ADJUSTGAL_ID      6
  63.  
  64.  
  65. #define PROG_EMPTY_ID     1             /* gadget IDs for write access */
  66. #define PROG_VERIFY_ID    2
  67. #define COPY_EMPTY_ID     3
  68. #define COPY_VERIFY_ID    4
  69. #define ERASE_EMPTY_ID    5
  70.  
  71.  
  72. #define JEDSEC_ID         1             /* gadget IDs for JEDEC parameter */
  73. #define JEDFUSE_ID        2
  74. #define JEDFILE_ID        3
  75.  
  76.  
  77. #define EDITORSTRING_ID   1             /* gadget IDs for editor selection */
  78.  
  79.  
  80. #define MAX_NUM_OF_LINES 20
  81.  
  82.  
  83.  
  84.  
  85.  
  86. /******************************** functions **********************************/
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93. /******************************** variables **********************************/
  94.  
  95. extern  struct  AppString { LONG   as_ID;
  96.                             STRPTR as_Str;
  97.                           };
  98.  
  99. extern  struct  AppString   AppStrings[];
  100.  
  101.  
  102. extern  struct  Catalog     *catalog;
  103.  
  104. extern  struct  timerequest *timereq;
  105.  
  106. extern  struct  rtFileRequester *filereq;
  107.  
  108. extern  int     GALType, MaxFuseAdr, RowSize, XORSize, SigAdr;
  109. extern  int     hw_version;
  110.  
  111. extern  APTR    app, main_win, LV_text;
  112.  
  113. extern  UBYTE   main_win_title[];
  114.  
  115.                                                 /* defaults: */
  116.  
  117. struct  Configuration Config = { GAL16V8,       /*GAL16V8*/
  118.                                  YES,           /*Requester für Typ*/
  119.                                  YES,           /*Jedec erzeugen*/
  120.                                  NO,            /*kein Fuse-File*/
  121.                                  NO,            /*kein Chip-File*/
  122.                                  NO,            /*kein Pin-File*/
  123.                                  NO,            /*kein Auto-Save*/
  124.                                  YES,           /*autom. GALTyp einstellen*/
  125.                                  YES,           /*Leertest vor GAL-Prog.*/
  126.                                  YES,           /*Verify nach GAL-Prog.*/
  127.                                  YES,           /*Leertest vor Copy-GAL*/
  128.                                  YES,           /*Verify nach Copy-GAL*/
  129.                                  YES,           /*Leertest nach GAL-Löschen*/
  130.                                  NO,            /*Sec.Bit der Jedec-Datei*/
  131.                                  YES,           /*Fuse-Checksumme der Jedec*/
  132.                                  NO,            /*File-Checksumme der Jedec*/
  133.                                  HW_GALER_1_3,  /*Hardware-Version*/
  134.                                  "run c:ed \"%s\""
  135.                                };
  136.  
  137.  
  138. struct  Configuration DummyConfig;              /* dummy for LoadConfig */
  139.  
  140.  
  141. UBYTE   ErrorLineStr[22];
  142.  
  143.  
  144. char    filename[108];                          /* buffer for filename   */
  145. char    path[108 + 130 + 4];                    /* buffer for directory, */
  146.                                                 /* filename and suffix   */
  147.  
  148. char    prevSourceFile[108 + 130 + 4];          /* name of the prev. */
  149.                                                 /* assembled file */
  150.  
  151. char    *cmps[4];
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159. /******************************************************************************
  160. ** Schreibverhalten()
  161. *******************************************************************************
  162. ** input:   none
  163. ** output:  none
  164. **
  165. ** remarks: opens a preferences window in which can be selected whether or
  166. **          not a programmed GAL should be verified or an empty test should
  167. **          be done before writing to a GAL
  168. **
  169. ******************************************************************************/
  170.  
  171. void Schreibverhalten(void)
  172. {
  173.     int   open, done;
  174.  
  175.     ULONG id, signals;
  176.  
  177.     APTR  win;
  178.     APTR  prog_empty, prog_verify, copy_empty, copy_verify, erase_empty;
  179.     APTR  ok;
  180.  
  181.  
  182.  
  183.  
  184.     set(app, MUIA_Application_Sleep, TRUE);     /* deactivate application */
  185.  
  186.  
  187.                                                 /* make window object */
  188.     win = WindowObject,
  189.         MUIA_Window_Title, AppStrings[MSG_WRITEACC_WIN].as_Str,
  190.         MUIA_Window_CloseGadget, FALSE,
  191.         MUIA_Window_NoMenus, TRUE,
  192.         MUIA_HelpNode, "MenWriteAcc",
  193.  
  194.             WindowContents, VGroup,
  195.                 Child, HGroup, GroupFrameT(AppStrings[MSG_PROG_ITXT].as_Str),
  196.                     Child, ColGroup(2),
  197.                         Child, Label1(AppStrings[MSG_BLANKTEST_GAD].as_Str),
  198.                         Child, prog_empty = CheckMark(Config.ProgEmptyTest),
  199.                         Child, Label1(AppStrings[MSG_VERIFY_GAD].as_Str),
  200.                         Child, prog_verify = CheckMark(Config.ProgVerify),
  201.                         End,
  202.                     End,
  203.  
  204.                 Child, HGroup, GroupFrameT(AppStrings[MSG_COPY_ITXT].as_Str),
  205.                     Child, ColGroup(2),
  206.                         Child, Label1(AppStrings[MSG_BLANKTEST_GAD].as_Str),
  207.                         Child, copy_empty = CheckMark(Config.CopyEmptyTest),
  208.                         Child, Label1(AppStrings[MSG_VERIFY_GAD].as_Str),
  209.                         Child, copy_verify = CheckMark(Config.CopyVerify),
  210.                         End,
  211.                     End,
  212.  
  213.                 Child, HGroup, GroupFrameT(AppStrings[MSG_ERASE_ITXT].as_Str),
  214.                     Child, ColGroup(2),
  215.                         Child, Label1(AppStrings[MSG_BLANKTEST_GAD].as_Str),
  216.                         Child, erase_empty = CheckMark(Config.EraseEmptyTest),
  217.                         End,
  218.                     End,
  219.  
  220.                 Child, HSpace(2),
  221.  
  222.                 Child, HGroup,
  223.                     Child, ok = SimpleButton(AppStrings[MSG_OK_GAD].as_Str),
  224.                     End,
  225.                 End,
  226.             End;
  227.  
  228.  
  229.                                         /* set gadget IDs */
  230.  
  231.     DoMethod(prog_empty, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  232.              app, 2, MUIM_Application_ReturnID, PROG_EMPTY_ID);
  233.  
  234.     DoMethod(prog_verify, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  235.              app, 2, MUIM_Application_ReturnID, PROG_VERIFY_ID);
  236.  
  237.     DoMethod(copy_empty, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  238.              app, 2, MUIM_Application_ReturnID, COPY_EMPTY_ID);
  239.  
  240.     DoMethod(copy_verify, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  241.              app, 2, MUIM_Application_ReturnID, COPY_VERIFY_ID);
  242.  
  243.     DoMethod(erase_empty, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  244.              app, 2, MUIM_Application_ReturnID, ERASE_EMPTY_ID);
  245.  
  246.     DoMethod(ok, MUIM_Notify, MUIA_Pressed, FALSE,
  247.              app, 2, MUIM_Application_ReturnID, OK_GADID);
  248.  
  249.  
  250.  
  251.                                         /* init cycle chain */
  252.  
  253.     DoMethod(win, MUIM_Window_SetCycleChain, prog_empty, prog_verify,
  254.              copy_empty, copy_verify, erase_empty, ok, NULL);
  255.  
  256.  
  257.  
  258.  
  259.     if (win)                    /* window object created? */
  260.     {
  261.         DoMethod(app, OM_ADDMEMBER, win);       /* add win to application */
  262.  
  263.         set(win, MUIA_Window_Open, TRUE);       /* open window */
  264.         get(win, MUIA_Window_Open, &open);
  265.  
  266.         if (open)                               /* is window opened? */
  267.         {
  268.  
  269.             done = FALSE;
  270.  
  271.             while (!done)
  272.             {
  273.                 id = DoMethod(app, MUIM_Application_Input, &signals);
  274.  
  275.                 switch (id)
  276.                 {
  277.                     case PROG_EMPTY_ID:
  278.                         Config.ProgEmptyTest = !Config.ProgEmptyTest;
  279.                         break;
  280.  
  281.                     case PROG_VERIFY_ID:
  282.                         Config.ProgVerify = !Config.ProgVerify;
  283.                         break;
  284.  
  285.                     case COPY_EMPTY_ID:
  286.                         Config.CopyEmptyTest = !Config.CopyEmptyTest;
  287.                         break;
  288.  
  289.                     case COPY_VERIFY_ID:
  290.                         Config.CopyVerify = !Config.CopyVerify;
  291.                         break;
  292.  
  293.                     case ERASE_EMPTY_ID:
  294.                         Config.EraseEmptyTest = !Config.EraseEmptyTest;
  295.                         break;
  296.  
  297.                     case OK_GADID:
  298.                     case MUIV_Application_ReturnID_Quit:
  299.                         done = TRUE;
  300.                         break;
  301.                 }
  302.  
  303.                 if (!done && signals)
  304.                     Wait(signals);              /* wait for the next event */
  305.             }
  306.  
  307.  
  308.            set(win, MUIA_Window_Open, FALSE);   /* close window */
  309.   
  310.         }
  311.  
  312.         DoMethod(app, OM_REMMEMBER, win);       /* remove win from app. */
  313.  
  314.         MUI_DisposeObject(win);                 /* delete window object */
  315.     }
  316.  
  317.  
  318.  
  319.     set(app, MUIA_Application_Sleep, FALSE);    /* reactivate application */
  320.  
  321. }
  322.  
  323.  
  324.  
  325.  
  326.  
  327. /******************************************************************************
  328. ** CompareRequester()
  329. *******************************************************************************
  330. ** input:   none
  331. ** output:  0: cancel selected or failed to open the window
  332. **          1: compare a GAL with one or several GALs
  333. **          2: compare a GAL with one or several JEDEC files
  334. **          3: compare a JEDEC file with one or several GALs
  335. **
  336. ** remarks: opens a window in which can be selected what kind of comparison
  337. **          should be executed
  338. **
  339. ******************************************************************************/
  340.  
  341. int CompareRequester(void)
  342. {
  343.     int   open, done, result;
  344.  
  345.     ULONG id, signals;
  346.  
  347.     APTR  win;
  348.     APTR  radio_buttons, cont, cancel;
  349.  
  350.  
  351.  
  352.     set(app, MUIA_Application_Sleep, TRUE);     /* deactivate application */
  353.  
  354.  
  355.                                                 /* make window object */
  356.     win = WindowObject,
  357.         MUIA_Window_Title, AppStrings[MSG_COMPARISON].as_Str,
  358.         MUIA_Window_CloseGadget, FALSE,
  359.         MUIA_Window_NoMenus, TRUE,
  360.         MUIA_HelpNode, "MenCmp",
  361.  
  362.             WindowContents, VGroup,
  363.                 Child, HCenter(radio_buttons = Radio(AppStrings[MSG_CMPTYPE].as_Str, cmps)),
  364.  
  365.                 Child, HSpace(2),
  366.  
  367.                 Child, HGroup,
  368.                     Child, cont   = SimpleButton(AppStrings[MSG_CONT_GAD].as_Str),
  369.                     Child, cancel = SimpleButton(AppStrings[MSG_CANCEL_GAD].as_Str),
  370.                     End,
  371.                 End,
  372.             End;
  373.  
  374.  
  375.                                         /* set gadget IDs */
  376.  
  377.     DoMethod(cont, MUIM_Notify, MUIA_Pressed, FALSE,
  378.              app, 2, MUIM_Application_ReturnID, CONT_GADID);
  379.  
  380.  
  381.     DoMethod(cancel, MUIM_Notify, MUIA_Pressed, FALSE,
  382.              app, 2, MUIM_Application_ReturnID, CANCEL_GADID);
  383.  
  384.  
  385.  
  386.                                         /* init cycle chain */
  387.  
  388.     DoMethod(win, MUIM_Window_SetCycleChain, radio_buttons, cont, cancel, NULL);
  389.  
  390.  
  391.  
  392.  
  393.     if (win)                    /* window object created? */
  394.     {
  395.         DoMethod(app, OM_ADDMEMBER, win);       /* add win to application */
  396.  
  397.         set(win, MUIA_Window_Open, TRUE);       /* open window */
  398.         get(win, MUIA_Window_Open, &open);
  399.  
  400.         if (open)                               /* is window opened? */
  401.         {
  402.  
  403.             done = FALSE;
  404.  
  405.             while (!done)
  406.             {
  407.                 id = DoMethod(app, MUIM_Application_Input, &signals);
  408.  
  409.                 switch (id)
  410.                 {
  411.                     case CANCEL_GADID:                      /* cancel */
  412.                     case MUIV_Application_ReturnID_Quit:
  413.                         done   = TRUE;
  414.                         result = 0;
  415.                         break;
  416.  
  417.                     case CONT_GADID:                        /* cont.  */
  418.                         get(radio_buttons, MUIA_Radio_Active, &result);
  419.                         result++;               /* get state of radio */
  420.                         done = TRUE;            /* buttons and return */
  421.                         break;                  /* the result         */
  422.                 }
  423.  
  424.                 if (!done && signals)
  425.                     Wait(signals);              /* wait for the next event */
  426.             }
  427.  
  428.  
  429.            set(win, MUIA_Window_Open, FALSE);   /* close window */
  430.  
  431.         }
  432.  
  433.         DoMethod(app, OM_REMMEMBER, win);       /* remove win from app. */
  434.  
  435.         MUI_DisposeObject(win);                 /* delete window object */
  436.     }
  437.  
  438.  
  439.  
  440.     set(app, MUIA_Application_Sleep, FALSE);    /* reactivate application */
  441.  
  442.  
  443.     return result;                              /* return result ;-) */
  444. }
  445.  
  446.  
  447.  
  448.  
  449.  
  450. /******************************************************************************
  451. ** JedecRequester()
  452. *******************************************************************************
  453. ** input:   none
  454. ** output:  none
  455. **
  456. ** remarks: opens the JEDEC preferences window
  457. **
  458. ******************************************************************************/
  459.  
  460. void JedecRequester(void)
  461. {
  462.  
  463.     int   open, done;
  464.  
  465.     ULONG id, signals;
  466.  
  467.     APTR  win;
  468.     APTR  sec, fuse, file, ok;
  469.  
  470.  
  471.  
  472.  
  473.     set(app, MUIA_Application_Sleep, TRUE);     /* deactivate application */
  474.  
  475.  
  476.                                                 /* make window object */
  477.     win = WindowObject,
  478.         MUIA_Window_Title, AppStrings[MSG_JEDPARA_WIN].as_Str,
  479.         MUIA_Window_CloseGadget, FALSE,
  480.         MUIA_Window_NoMenus, TRUE,
  481.         MUIA_HelpNode, "MenJEDECPar",
  482.  
  483.             WindowContents, VGroup,
  484.                 Child, HGroup, GroupFrameT(AppStrings[MSG_WRITEJED_ITXT].as_Str),
  485.                     Child, ColGroup(2),
  486.                         Child, Label1(AppStrings[MSG_JEDSEC_GAD].as_Str),
  487.                         Child, sec = CheckMark(Config.JedecSecBit),
  488.                         Child, Label1(AppStrings[MSG_JEDFUSE_GAD].as_Str),
  489.                         Child, fuse = CheckMark(Config.JedecFuseChk),
  490.                         Child, Label1(AppStrings[MSG_JEDFILE_GAD].as_Str),
  491.                         Child, file = CheckMark(Config.JedecFileChk),
  492.                         End,
  493.                     End,
  494.  
  495.                 Child, HSpace(2),
  496.  
  497.                 Child, HGroup,
  498.                     Child, ok = SimpleButton(AppStrings[MSG_OK_GAD].as_Str),
  499.                     End,
  500.                 End,
  501.             End;
  502.  
  503.  
  504.                                         /* set gadget IDs */
  505.  
  506.     DoMethod(sec, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  507.              app, 2, MUIM_Application_ReturnID, JEDSEC_ID);
  508.  
  509.     DoMethod(fuse, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  510.              app, 2, MUIM_Application_ReturnID, JEDFUSE_ID);
  511.  
  512.     DoMethod(file, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  513.              app, 2, MUIM_Application_ReturnID, JEDFILE_ID);
  514.  
  515.     DoMethod(ok, MUIM_Notify, MUIA_Pressed, FALSE,
  516.              app, 2, MUIM_Application_ReturnID, OK_GADID);
  517.  
  518.  
  519.  
  520.                                         /* init cycle chain */
  521.  
  522.     DoMethod(win, MUIM_Window_SetCycleChain, sec, fuse, file, ok, NULL);
  523.  
  524.  
  525.  
  526.     if (win)                    /* window object created? */
  527.     {
  528.         DoMethod(app, OM_ADDMEMBER, win);       /* add win to application */
  529.  
  530.         set(win, MUIA_Window_Open, TRUE);       /* open window */
  531.         get(win, MUIA_Window_Open, &open);
  532.  
  533.         if (open)                               /* is window opened? */
  534.         {
  535.  
  536.             done = FALSE;
  537.  
  538.             while (!done)
  539.             {
  540.                 id = DoMethod(app, MUIM_Application_Input, &signals);
  541.  
  542.                 switch (id)
  543.                 {
  544.                     case JEDSEC_ID:
  545.                         Config.JedecSecBit = !Config.JedecSecBit;
  546.                         break;
  547.  
  548.                     case JEDFUSE_ID:
  549.                         Config.JedecFuseChk = !Config.JedecFuseChk;
  550.                         break;
  551.  
  552.                     case JEDFILE_ID:
  553.                         Config.JedecFileChk = !Config.JedecFileChk;
  554.                         break;
  555.  
  556.                     case OK_GADID:
  557.                         done = TRUE;
  558.                         break;
  559.                 }
  560.  
  561.                 if (!done && signals)
  562.                     Wait(signals);              /* wait for the next event */
  563.             }
  564.  
  565.  
  566.            set(win, MUIA_Window_Open, FALSE);   /* close window */
  567.   
  568.         }
  569.  
  570.         DoMethod(app, OM_REMMEMBER, win);       /* remove win from app. */
  571.  
  572.         MUI_DisposeObject(win);                 /* delete window object */
  573.     }
  574.  
  575.  
  576.  
  577.     set(app, MUIA_Application_Sleep, FALSE);    /* reactivate application */
  578.  
  579. }
  580.  
  581.  
  582.  
  583.  
  584.  
  585. /******************************************************************************
  586. ** About()
  587. *******************************************************************************
  588. ** input:   none
  589. ** output:  none
  590. **
  591. ** remarks: opens the about window
  592. ******************************************************************************/
  593.  
  594. void About(void)
  595. {
  596.     int   open, done;
  597.  
  598.     ULONG id, signals;
  599.  
  600.     APTR  win;
  601.     APTR  ok;
  602.  
  603.  
  604.  
  605.     set(app, MUIA_Application_Sleep, TRUE);     /* deactivate application */
  606.  
  607.                                                 /* make window object */
  608.     win = WindowObject,
  609.         MUIA_Window_Title, AppStrings[MSG_MAIN_MENU1_ITEM1].as_Str,
  610.         MUIA_Window_CloseGadget, FALSE,
  611.         MUIA_Window_NoMenus, TRUE,
  612.         MUIA_HelpNode, "MenAbout",
  613.  
  614.             WindowContents, VGroup,
  615.                 Child, TextObject, TextFrame, MUIA_Background, MUII_TextBack, MUIA_Text_Contents, AppStrings[MSG_ABOUT_TXT].as_Str, End,
  616.                 Child, ok = SimpleButton(AppStrings[MSG_OK_GAD].as_Str),
  617.                 End,
  618.             End;
  619.  
  620.  
  621.                                         /* set gadget IDs */
  622.  
  623.     DoMethod(ok, MUIM_Notify, MUIA_Pressed, FALSE,
  624.              app, 2, MUIM_Application_ReturnID, OK_GADID);
  625.  
  626.  
  627.  
  628.                                         /* init cycle chain */
  629.  
  630.     DoMethod(win, MUIM_Window_SetCycleChain, ok, NULL);
  631.  
  632.  
  633.  
  634.  
  635.     if (win)                    /* window object created? */
  636.     {
  637.         DoMethod(app, OM_ADDMEMBER, win);       /* add win to application */
  638.  
  639.         set(win, MUIA_Window_Open, TRUE);       /* open window */
  640.         get(win, MUIA_Window_Open, &open);
  641.  
  642.         if (open)                               /* is window opened? */
  643.         {
  644.  
  645.             done = FALSE;
  646.  
  647.             while (!done)
  648.             {
  649.                 id = DoMethod(app, MUIM_Application_Input, &signals);
  650.  
  651.                 switch (id)
  652.                 {
  653.                     case OK_GADID:                          /* continue */
  654.                     case MUIV_Application_ReturnID_Quit:
  655.                         done   = TRUE;
  656.                         break;
  657.                 }
  658.  
  659.                 if (!done && signals)
  660.                     Wait(signals);              /* wait for the next event */
  661.             }
  662.  
  663.  
  664.            set(win, MUIA_Window_Open, FALSE);   /* close window */
  665.  
  666.         }
  667.  
  668.         DoMethod(app, OM_REMMEMBER, win);       /* remove win from app. */
  669.  
  670.         MUI_DisposeObject(win);                 /* delete window object */
  671.     }
  672.  
  673.  
  674.  
  675.     set(app, MUIA_Application_Sleep, FALSE);    /* reactivate application */
  676.  
  677. }
  678.  
  679.  
  680.  
  681.  
  682.  
  683. /******************************************************************************
  684. ** mystrcmp()
  685. *******************************************************************************
  686. ** input:   *cptr1      pointer to string 1
  687. **          *cptr2      pointer to string 2
  688. **
  689. ** output:  TRUE        strings are not equal
  690. **          FALSE       strings are equal
  691. **
  692. ** remarks: This function does compare two strings (deals upper and lower
  693. **          case as the same).
  694. ******************************************************************************/
  695.  
  696. int mystrcmp(char *cptr1, char *cptr2)
  697. {
  698.  
  699.     while (*cptr1 && *cptr2)
  700.     {
  701.         if (tolower(*cptr1) != tolower(*cptr2))
  702.             return TRUE;
  703.  
  704.         cptr1++;
  705.         cptr2++;
  706.     }
  707.  
  708.  
  709.     if (!*cptr1 && !*cptr2)
  710.         return FALSE;
  711.     else
  712.         return TRUE;
  713.  
  714. }
  715.  
  716.  
  717.  
  718.  
  719.  
  720. /******************************************************************************
  721. ** MyFileReq()
  722. *******************************************************************************
  723. ** input:   *headtxt   requester title
  724. **          *showtxt   suffix
  725. **          showreq    TRUE:  show requester
  726. **                     FALSE: show no requester
  727. **          mode       SAVE/LOAD  save/load-requester
  728. **
  729. ** output:  TRUE    o.k. selected
  730. **          FALSE   cancel selected
  731. **
  732. ** remarks: opens the reqtools-file-requester
  733. ******************************************************************************/
  734.  
  735. int MyFileReq(char *headtxt, char *showtxt, int showreq, int mode)
  736. {
  737.     int     freq = YES, result;
  738.     char    *pos1, *pos2, *str_buf;
  739.     char    showpattern[10] = "#?";
  740.     char    short_path[35];
  741.  
  742.     struct  FileLock *lock;
  743.  
  744.  
  745.  
  746.     strcat(showpattern, showtxt);         /* make show pattern */
  747.  
  748.     rtChangeReqAttr(filereq, RTFI_MatchPat, showpattern, TAG_END);
  749.  
  750.                                          /* remove suffix and add "showtxt" */
  751.     if (strlen((char *)filename) >= 4)
  752.     {
  753.         pos1 = (char *)(filename + (long)strlen(filename) -
  754.                         (long)strlen(showtxt));
  755.  
  756.         if ((!mystrcmp(pos1, ".pld")) || (!mystrcmp(pos1, ".jed")) ||
  757.             (!mystrcmp(pos1, ".pin")) || (!mystrcmp(pos1, ".chp")) ||
  758.             (!mystrcmp(pos1, ".fus")))
  759.         {
  760.             *pos1 = 0;
  761.             strcat((char *)&filename[0], showtxt);
  762.         }
  763.     }
  764.  
  765.  
  766.  
  767.     if (showreq)                           /* show requester? */
  768.     {
  769.         set(app, MUIA_Application_Sleep, TRUE);    /* deactivate application */
  770.  
  771.         freq = (int)rtFileRequest(filereq, filename, headtxt,
  772.                                   RT_ReqPos,  REQPOS_CENTERSCR,
  773.                                   RTFI_Flags, FREQF_PATGAD, TAG_END);
  774.  
  775.         set(app, MUIA_Application_Sleep, FALSE);   /* reactivate application */
  776.     }
  777.  
  778.  
  779.     if ((showreq && freq) || !showreq)
  780.     {
  781.  
  782.         if (strlen((char *)filename) >= 4)
  783.         {                                       /* add suffix */
  784.  
  785.             pos1 = (char *)(filename + (long)strlen(filename) -
  786.                            (long)strlen(showtxt));
  787.  
  788.             if (mystrcmp(pos1, showtxt))   /* add suffix if there is none */
  789.             {
  790.                 strcat(filename, showtxt);
  791.                 strcat(path, showtxt);
  792.             }
  793.  
  794.         }
  795.         else
  796.         {
  797.  
  798.             if (!strlen(filename))           /* no file entered? */
  799.                 return FALSE;                /* then cancel      */
  800.  
  801.             strcat(filename, showtxt);
  802.             strcat(path, showtxt);
  803.         }
  804.  
  805.  
  806.                                             /* compose path */
  807.         strcpy(path, filereq->Dir);
  808.  
  809.         pos1 = (char *)(filereq->Dir + ((long)strlen(filereq->Dir) - 1L));
  810.         pos2 = (char *)(path + ((long)strlen(path)));
  811.  
  812.         if (!((*pos1 == ':') || (*pos1 == '/') || !*pos1))
  813.         {
  814.             *pos2++ = '/';
  815.             *pos2   = 0x00;                 /* end of string */
  816.         }
  817.  
  818.         strcat(path, filename);
  819.  
  820.  
  821.  
  822.         if (!strcmp(showtxt, ".pld"))       /* copy dir+filename of the */
  823.             strcpy(prevSourceFile, path);   /* source file to buffer */
  824.  
  825.  
  826.  
  827.         if (showreq && (mode == SAVE))      /* if this is a SAVE-requester   */
  828.         {                                   /* test whether or not this file */
  829.                                             /* does already exist            */
  830.  
  831.             if ((lock = (struct FileLock *)Lock((BYTE *)path,
  832.                                                 (long)ACCESS_READ)))
  833.             {
  834.                 UnLock((BPTR)lock);
  835.  
  836.                 set(app, MUIA_Application_Sleep, TRUE);   /* let appl. sleep */
  837.  
  838.                                                 /* show text: "file 'xyz' */
  839.                                                 /* already exists" */
  840.                 if ((str_buf = (char *)AllocMem(
  841.                                     strlen(AppStrings[MSG_SAVEOVER].as_Str) +
  842.                                     sizeof(short_path), MEMF_PUBLIC)))
  843.                 {
  844.                                                 /* limit length of path name */
  845.  
  846.                     if (strlen(path) > sizeof(short_path) - 1)
  847.                     {
  848.                         short_path[0] = '.';    /* make path shorter */
  849.                         short_path[1] = '.';
  850.                         short_path[2] = '.';
  851.                         short_path[3] = 0;
  852.  
  853.                         strcat(short_path,
  854.                                &path[strlen(path) - sizeof(short_path) + 5]);
  855.                     }
  856.                     else
  857.                     {
  858.                         strcpy(short_path, path);
  859.                     }
  860.                                             /* make text to be displayed */
  861.  
  862.                     sprintf(str_buf, AppStrings[MSG_SAVEOVER].as_Str,
  863.                                                                 short_path);
  864.                     result = TxtRequest(str_buf,
  865.                                         AppStrings[MSG_CONT_GAD].as_Str,
  866.                                         AppStrings[MSG_CANCEL_GAD].as_Str);
  867.                     FreeMem(str_buf, strlen(AppStrings[MSG_SAVEOVER].as_Str) +
  868.                                      sizeof(short_path));
  869.                 }
  870.  
  871.  
  872.                 set(app, MUIA_Application_Sleep, FALSE);   /* wake up appl. */
  873.  
  874.                 if (!result)               /* call again, if canceled */
  875.                     return (MyFileReq(headtxt, showtxt, showreq, mode));
  876.             }
  877.         }
  878.  
  879.         return TRUE;
  880.  
  881.     }
  882.     else
  883.     {
  884.         return FALSE;
  885.     }
  886.  
  887.     return FALSE;           /* just to keep the compiler happy */
  888. }
  889.  
  890.  
  891.  
  892.  
  893.  
  894. /******************************************************************************
  895. ** TxtRequest()
  896. *******************************************************************************
  897. ** input:   *text           text to show
  898. **          *gadget1_txt    text for first gadget
  899. **          *gadget2_txt    text for second gadget
  900. **
  901. ** output:  one gadget:   0: error or gadget selected
  902. **          two gadgets:  0: error or second gadget selected
  903. **                        1: first gadget selected
  904. **
  905. ** remarks: This function opens a requester with one or two gadgets. If
  906. **          *gadget2_txt is NULL, only one gadget is displayed else two.
  907. **          The parameter *gadget1_txt must always be not equal NULL!
  908. ******************************************************************************/
  909.  
  910. int TxtRequest(UBYTE *text, UBYTE *gadget1_txt, UBYTE *gadget2_txt)
  911. {
  912.     int   result;
  913.     int   open, done;
  914.  
  915.     ULONG id, signals;
  916.  
  917.     APTR  win;
  918.     APTR  gad1, gad2;
  919.  
  920.  
  921.  
  922.     set(app, MUIA_Application_Sleep, TRUE);   /* deactivate the application */
  923.  
  924.  
  925.                                                 /* make window object */
  926.     if (gadget2_txt)
  927.     {
  928.         win = WindowObject,
  929.             MUIA_Window_Title, AppStrings[MSG_REQUEST_WIN].as_Str,
  930.             MUIA_Window_CloseGadget, FALSE,
  931.             MUIA_Window_NoMenus, TRUE,
  932.             MUIA_HelpNode, "Main",
  933.  
  934.                 WindowContents, VGroup,
  935.                     Child, TextObject, TextFrame, MUIA_Background, MUII_TextBack, MUIA_Text_Contents, text, End,
  936.                     Child, HGroup,
  937.                         Child, gad1 = SimpleButton(gadget1_txt),
  938.                         Child, gad2 = SimpleButton(gadget2_txt),
  939.                         End,
  940.                     End,
  941.                 End;
  942.                                         /* set gadget IDs */
  943.  
  944.         DoMethod(gad1, MUIM_Notify, MUIA_Pressed, FALSE,
  945.              app, 2, MUIM_Application_ReturnID, 2);
  946.  
  947.         DoMethod(gad2, MUIM_Notify, MUIA_Pressed, FALSE,
  948.              app, 2, MUIM_Application_ReturnID, 1);
  949.  
  950.                                         /* init cycle chain */
  951.  
  952.         DoMethod(win, MUIM_Window_SetCycleChain, gad1, gad2, NULL);
  953.     }
  954.     else
  955.     {
  956.         win = WindowObject,
  957.             MUIA_Window_Title, AppStrings[MSG_REQUEST_WIN].as_Str,
  958.             MUIA_Window_CloseGadget, FALSE,
  959.             MUIA_Window_NoMenus, TRUE,
  960.             MUIA_HelpNode, "Main",
  961.  
  962.                 WindowContents, VGroup,
  963.                     Child, TextObject, TextFrame, MUIA_Background, MUII_TextBack, MUIA_Text_Contents, text, End,
  964.                     Child, gad1 = SimpleButton(gadget1_txt),
  965.                     End,
  966.                 End;
  967.                                         /* set gadget IDs */
  968.  
  969.         DoMethod(gad1, MUIM_Notify, MUIA_Pressed, FALSE,
  970.              app, 2, MUIM_Application_ReturnID, 1);
  971.  
  972.                                         /* init cycle chain */
  973.  
  974.         DoMethod(win, MUIM_Window_SetCycleChain, gad1, NULL);
  975.     }
  976.  
  977.  
  978.  
  979.  
  980.     if (win)                    /* window object created? */
  981.     {
  982.         DoMethod(app, OM_ADDMEMBER, win);       /* add win to application */
  983.  
  984.         set(win, MUIA_Window_Open, TRUE);       /* open window */
  985.         get(win, MUIA_Window_Open, &open);
  986.  
  987.         if (open)                               /* is window opened? */
  988.         {
  989.  
  990.             done = FALSE;
  991.  
  992.             while (!done)
  993.             {
  994.                 id = DoMethod(app, MUIM_Application_Input, &signals);
  995.  
  996.                 switch (id)
  997.                 {
  998.                     case 1:
  999.                     case MUIV_Application_ReturnID_Quit:
  1000.                         done   = TRUE;
  1001.                         result = 0;
  1002.                         break;
  1003.  
  1004.                     case 2:
  1005.                         done   = TRUE;
  1006.                         result = 1;
  1007.                         break;
  1008.                 }
  1009.  
  1010.                 if (!done && signals)
  1011.                     Wait(signals);              /* wait for the next event */
  1012.             }
  1013.  
  1014.  
  1015.            set(win, MUIA_Window_Open, FALSE);   /* close window */
  1016.  
  1017.         }
  1018.  
  1019.         DoMethod(app, OM_REMMEMBER, win);       /* remove win from app. */
  1020.  
  1021.         MUI_DisposeObject(win);                 /* delete window object */
  1022.     }
  1023.  
  1024.  
  1025.     set(app, MUIA_Application_Sleep, FALSE);    /* reactivate application */
  1026.  
  1027.  
  1028.     return result;
  1029. }
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035. /******************************************************************************
  1036. ** GALTypeRequest()
  1037. *******************************************************************************
  1038. ** input:   *text   text to show
  1039. **
  1040. ** output:  0       cancel or error
  1041. **          1       GAL16V8 selected
  1042. **          2       GAL20V8 selected
  1043. **          3       GAL22V10 selected
  1044. **          4       GAL20RA10 selected
  1045. **
  1046. ** remarks: This function opens a requester in which a GAL type can be
  1047. **          selected, if the GAL type selection option is true.
  1048. **          If the GAL type selection option is not active, a continue/cancel
  1049. **          requester will be opened.
  1050. ******************************************************************************/
  1051.  
  1052. int GALTypeRequest(UBYTE *text)
  1053. {
  1054.     int   open, done, result;
  1055.  
  1056.     ULONG id, signals;
  1057.  
  1058.     APTR  win;
  1059.     APTR  radio_buttons, cont, cancel;
  1060.  
  1061.     static char *radio_txt[5];
  1062.  
  1063.  
  1064.  
  1065.     result = 0;
  1066.  
  1067.  
  1068.     if (Config.GALTypeReq)                    /* GAL type selection active? */
  1069.     {
  1070.  
  1071.         if (hw_version <= HW_GALER_1_2)       /* init text of radio buttons */
  1072.         {
  1073.             radio_txt[0] = "GAL16V8";
  1074.             radio_txt[1] = "GAL20V8";
  1075.             radio_txt[2] = NULL;
  1076.         }
  1077.         else
  1078.         {
  1079.             radio_txt[0] = "GAL16V8";
  1080.             radio_txt[1] = "GAL20V8";
  1081.             radio_txt[2] = "GAL22V10";
  1082.             radio_txt[3] = "GAL20RA10";
  1083.             radio_txt[4] = NULL;
  1084.         }
  1085.  
  1086.  
  1087.  
  1088.         set(app, MUIA_Application_Sleep, TRUE);   /* deactivate application */
  1089.  
  1090.  
  1091.                                             /* make window object */
  1092.         win = WindowObject,
  1093.             MUIA_Window_Title, NULL,
  1094.             MUIA_Window_CloseGadget, FALSE,
  1095.             MUIA_Window_NoMenus, TRUE,
  1096.             MUIA_HelpNode, "MenTypeReq",
  1097.  
  1098.                 WindowContents, VGroup,
  1099.                     Child, TextObject, TextFrame, MUIA_Background, MUII_TextBack, MUIA_Text_Contents, text, End,
  1100.  
  1101.                     Child, HCenter(radio_buttons = Radio(AppStrings[MSG_MAIN_MENU2].as_Str, radio_txt)),
  1102.  
  1103.                     Child, HSpace(2),
  1104.  
  1105.                     Child, HGroup,
  1106.                         Child, cont   = SimpleButton(AppStrings[MSG_CONT_GAD].as_Str),
  1107.                         Child, cancel = SimpleButton(AppStrings[MSG_CANCEL_GAD].as_Str),
  1108.                         End,
  1109.                     End,
  1110.                 End;
  1111.  
  1112.  
  1113.                                             /* set gadget IDs */
  1114.  
  1115.         DoMethod(cont, MUIM_Notify, MUIA_Pressed, FALSE,
  1116.                  app, 2, MUIM_Application_ReturnID, CONT_GADID);
  1117.  
  1118.  
  1119.         DoMethod(cancel, MUIM_Notify, MUIA_Pressed, FALSE,
  1120.                  app, 2, MUIM_Application_ReturnID, CANCEL_GADID);
  1121.  
  1122.  
  1123.                                             /* init cycle chain */
  1124.  
  1125.         DoMethod(win, MUIM_Window_SetCycleChain, radio_buttons, cont, cancel, NULL);
  1126.  
  1127.  
  1128.                                             /* activate current GAL-type gadget */
  1129.         switch (GALType)
  1130.         {
  1131.             case GAL16V8:
  1132.                 set(radio_buttons, MUIA_Radio_Active, 0);
  1133.                 break;
  1134.  
  1135.             case GAL20V8:
  1136.                 set(radio_buttons, MUIA_Radio_Active, 1);
  1137.                 break;
  1138.  
  1139.             case GAL22V10:
  1140.                 set(radio_buttons, MUIA_Radio_Active, 2);
  1141.                 break;
  1142.  
  1143.             case GAL20RA10:
  1144.                 set(radio_buttons, MUIA_Radio_Active, 3);
  1145.                 break;
  1146.          }
  1147.  
  1148.  
  1149.  
  1150.         if (win)                    /* window object created? */
  1151.         {
  1152.             DoMethod(app, OM_ADDMEMBER, win);       /* add win to application */
  1153.  
  1154.             set(win, MUIA_Window_Open, TRUE);       /* open window */
  1155.             get(win, MUIA_Window_Open, &open);
  1156.  
  1157.             if (open)                               /* is window opened? */
  1158.             {
  1159.  
  1160.                 done = FALSE;
  1161.  
  1162.                 while (!done)
  1163.                 {
  1164.                     id = DoMethod(app, MUIM_Application_Input, &signals);
  1165.  
  1166.                     switch (id)
  1167.                     {
  1168.                         case CANCEL_GADID:                      /* cancel */
  1169.                         case MUIV_Application_ReturnID_Quit:
  1170.                             done   = TRUE;
  1171.                             result = 0;
  1172.                             break;
  1173.  
  1174.                         case CONT_GADID:                        /* cont.  */
  1175.                             get(radio_buttons, MUIA_Radio_Active, &result);
  1176.                             result++;               /* get state of radio */
  1177.                             done = TRUE;            /* buttons and return */
  1178.                             break;                  /* the result         */
  1179.                     }
  1180.  
  1181.                     if (!done && signals)
  1182.                         Wait(signals);              /* wait for the next event */
  1183.                 }
  1184.  
  1185.  
  1186.                set(win, MUIA_Window_Open, FALSE);   /* close window */
  1187.  
  1188.             }
  1189.  
  1190.             DoMethod(app, OM_REMMEMBER, win);       /* remove win from app. */
  1191.  
  1192.             MUI_DisposeObject(win);                 /* delete window object */
  1193.         }
  1194.  
  1195.  
  1196.  
  1197.         set(app, MUIA_Application_Sleep, FALSE);  /* reactivate application */
  1198.  
  1199.  
  1200.  
  1201.         switch(result)
  1202.         {
  1203.             case 1:
  1204.                 SetGALType(GAL16V8);        /* GAL16V8 selected */
  1205.                 break;
  1206.  
  1207.             case 2:
  1208.                 SetGALType(GAL20V8);        /* GAL20V8 selected */
  1209.                 break;
  1210.  
  1211.             case 3:
  1212.                 SetGALType(GAL22V10);       /* GAL22V10 selected */
  1213.                 break;
  1214.  
  1215.             case 4:
  1216.                 SetGALType(GAL20RA10);      /* GAL20RA10 selected */
  1217.                 break;
  1218.         }
  1219.  
  1220.     }
  1221.     else
  1222.     {
  1223.         result = TxtRequest(text, AppStrings[MSG_CONT_GAD].as_Str,
  1224.                                   AppStrings[MSG_CANCEL_GAD].as_Str);
  1225.     }
  1226.  
  1227.  
  1228.     return result;
  1229. }
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235. /******************************************************************************
  1236. ** AsmRequest()
  1237. *******************************************************************************
  1238. ** input:   none
  1239. **
  1240. ** output:  TRUE   continue selected
  1241. **          FALSE  cancel selected
  1242. **
  1243. ** remarks: opens the assembler options window
  1244. **
  1245. ******************************************************************************/
  1246.  
  1247. int AsmRequester(void)
  1248. {
  1249.     int   open, done, result;
  1250.  
  1251.     ULONG id, signals;
  1252.  
  1253.     APTR  win;
  1254.     APTR  cont, cancel;
  1255.     APTR  jedec, fuse, chip, pin, autosave, type;
  1256.  
  1257.  
  1258.  
  1259.  
  1260.     set(app, MUIA_Application_Sleep, TRUE);     /* deactivate application */
  1261.  
  1262.  
  1263.                                                 /* make window object */
  1264.     win = WindowObject,
  1265.         MUIA_Window_Title, "Assembler",
  1266.         MUIA_Window_CloseGadget, FALSE,
  1267.         MUIA_Window_NoMenus, TRUE,
  1268.         MUIA_HelpNode, "Assembler",
  1269.  
  1270.             WindowContents, VGroup,
  1271.                 Child, HGroup, GroupFrameT(AppStrings[MSG_WRITEFILES_ITXT].as_Str),
  1272.                     Child, ColGroup(2),
  1273.                         Child, Label1(AppStrings[MSG_MAKEJED_GAD].as_Str),
  1274.                         Child, jedec = CheckMark(Config.GenJedec),
  1275.                         Child, Label1(AppStrings[MSG_MAKEFUSE_GAD].as_Str),
  1276.                         Child, fuse = CheckMark(Config.GenFuse),
  1277.                         Child, Label1(AppStrings[MSG_MAKECHIP_GAD].as_Str),
  1278.                         Child, chip = CheckMark(Config.GenChip),
  1279.                         Child, Label1(AppStrings[MSG_MAKEPIN_GAD].as_Str),
  1280.                         Child, pin = CheckMark(Config.GenPin),
  1281.                        End,
  1282.                     End,
  1283.  
  1284.                 Child, HGroup,
  1285.                     Child, ColGroup(2),
  1286.                         Child, Label1(AppStrings[MSG_AUTOSAVE_GAD].as_Str),
  1287.                         Child, autosave = CheckMark(Config.AutoSave),
  1288.                         Child, Label1(AppStrings[MSG_ADJUSTGAL_GAD].as_Str),
  1289.                         Child, type = CheckMark(Config.AutoGAL),
  1290.                         End,
  1291.                     End,
  1292.  
  1293.                 Child, HSpace(2),
  1294.  
  1295.                 Child, HGroup,
  1296.                     Child, cont   = SimpleButton(AppStrings[MSG_CONT_GAD].as_Str),
  1297.  
  1298.                     Child, VSpace(4),
  1299.  
  1300.                     Child, cancel = SimpleButton(AppStrings[MSG_CANCEL_GAD].as_Str),
  1301.                     End,
  1302.                 End,
  1303.             End;
  1304.  
  1305.  
  1306.                                         /* set gadget IDs */
  1307.  
  1308.     DoMethod(jedec, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  1309.              app, 2, MUIM_Application_ReturnID, MAKEJED_ID);
  1310.  
  1311.     DoMethod(fuse, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  1312.              app, 2, MUIM_Application_ReturnID, MAKEFUSE_ID);
  1313.  
  1314.     DoMethod(chip, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  1315.              app, 2, MUIM_Application_ReturnID, MAKECHIP_ID);
  1316.  
  1317.     DoMethod(pin, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  1318.              app, 2, MUIM_Application_ReturnID, MAKEPIN_ID);
  1319.  
  1320.     DoMethod(autosave, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  1321.              app, 2, MUIM_Application_ReturnID, AUTOSAVE_ID);
  1322.  
  1323.     DoMethod(type, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  1324.              app, 2, MUIM_Application_ReturnID, ADJUSTGAL_ID);
  1325.  
  1326.     DoMethod(cont, MUIM_Notify, MUIA_Pressed, FALSE,
  1327.              app, 2, MUIM_Application_ReturnID, CONT_GADID);
  1328.  
  1329.     DoMethod(cancel, MUIM_Notify, MUIA_Pressed, FALSE,
  1330.              app, 2, MUIM_Application_ReturnID, CANCEL_GADID);
  1331.  
  1332.  
  1333.  
  1334.                                         /* init cycle chain */
  1335.  
  1336.     DoMethod(win, MUIM_Window_SetCycleChain, jedec, fuse, chip, pin,
  1337.              autosave, type, cont, cancel, NULL);
  1338.  
  1339.  
  1340.  
  1341.     if (win)                    /* window object created? */
  1342.     {
  1343.         DoMethod(app, OM_ADDMEMBER, win);       /* add win to application */
  1344.  
  1345.         set(win, MUIA_Window_Open, TRUE);       /* open window */
  1346.         get(win, MUIA_Window_Open, &open);
  1347.  
  1348.         if (open)                               /* is window opened? */
  1349.         {
  1350.  
  1351.             done = FALSE;
  1352.  
  1353.             while (!done)
  1354.             {
  1355.                 id = DoMethod(app, MUIM_Application_Input, &signals);
  1356.  
  1357.                 switch (id)
  1358.                 {
  1359.                     case CONT_GADID:         /* continue */
  1360.                         done = TRUE;
  1361.                         result = TRUE;
  1362.                         break;
  1363.  
  1364.                     case CANCEL_GADID:       /* cancel */
  1365.                         done = TRUE;
  1366.                         result = FALSE;
  1367.                         break;
  1368.  
  1369.                     case MAKEJED_ID:
  1370.                         Config.GenJedec = !Config.GenJedec;
  1371.                         break;
  1372.  
  1373.                     case MAKEFUSE_ID:
  1374.                         Config.GenFuse = !Config.GenFuse;
  1375.                         break;
  1376.  
  1377.                     case MAKECHIP_ID:
  1378.                         Config.GenChip = !Config.GenChip;
  1379.                         break;
  1380.  
  1381.                     case MAKEPIN_ID:
  1382.                         Config.GenPin = !Config.GenPin;
  1383.                         break;
  1384.  
  1385.                     case AUTOSAVE_ID:
  1386.                         Config.AutoSave = !Config.AutoSave;
  1387.                         break;
  1388.  
  1389.                     case ADJUSTGAL_ID:
  1390.                         Config.AutoGAL = !Config.AutoGAL;
  1391.                         break;
  1392.                 }
  1393.  
  1394.                 if (signals && !done)
  1395.                     Wait(signals);              /* wait for the next event */
  1396.             }
  1397.  
  1398.  
  1399.            set(win, MUIA_Window_Open, FALSE);   /* close window */
  1400.   
  1401.         }
  1402.  
  1403.         DoMethod(app, OM_REMMEMBER, win);       /* remove win from app. */
  1404.  
  1405.         MUI_DisposeObject(win);                 /* delete window object */
  1406.     }
  1407.  
  1408.  
  1409.     set(app, MUIA_Application_Sleep, FALSE);    /* reactivate application */
  1410.  
  1411.     return result;
  1412. }
  1413.  
  1414.  
  1415.  
  1416.  
  1417.  
  1418. /******************************************************************************
  1419. ** FileSize()
  1420. *******************************************************************************
  1421. ** input:   *filename   filename
  1422. **
  1423. ** output:  -1   file does not exist
  1424. **          -2   not enough memory for FileInfoBlock
  1425. **          >0   length of the specified file
  1426. **
  1427. ** remarks: returns length of a file
  1428. **
  1429. ******************************************************************************/
  1430.  
  1431. long FileSize(UBYTE *filename)
  1432. {
  1433.     struct  FileInfoBlock  *fib;
  1434.     struct  FileLock       *lock;
  1435.     LONG    filesize;
  1436.  
  1437.  
  1438.     if ((lock = (struct FileLock *)Lock((BYTE *)filename, (long)ACCESS_READ)))
  1439.     {
  1440.  
  1441.         fib = (struct FileInfoBlock *)
  1442.               AllocMem((long)sizeof(struct FileInfoBlock), MEMF_CHIP);
  1443.  
  1444.         if (fib != NULL)
  1445.         {
  1446.             if (Examine((BPTR)lock, fib))
  1447.                 filesize = fib->fib_Size;
  1448.             else
  1449.                 filesize = -1L;
  1450.  
  1451.             UnLock((BPTR)lock);
  1452.  
  1453.             FreeMem(fib,(long)sizeof(struct FileInfoBlock));
  1454.  
  1455.             return (filesize);
  1456.         }
  1457.         else
  1458.         {
  1459.             return -2L;                         /* not enough free memory */
  1460.         }
  1461.     }
  1462.     else
  1463.     {
  1464.         return -1L;                             /* file does not exist */
  1465.     }
  1466. }
  1467.  
  1468.  
  1469.  
  1470.  
  1471.  
  1472. /******************************************************************************
  1473. ** ReadFile()
  1474. *******************************************************************************
  1475. ** input:   *filename       name of file
  1476. **          filesize        length of file [bytes]
  1477. **          *filebuff       where to store the specified file
  1478. **
  1479. ** output:  TRUE:  file loaded
  1480. **          FALSE: failed to load
  1481. **
  1482. ** remarks: loads the specified file into memory
  1483. **
  1484. ******************************************************************************/
  1485.  
  1486. int ReadFile(UBYTE *filename, LONG filesize, UBYTE *filebuff)
  1487. {
  1488.     long  actlength;
  1489.     BPTR  fh;
  1490.  
  1491.  
  1492.     if ((fh = Open((char *)filename, (long)MODE_OLDFILE)))
  1493.     {
  1494.         actlength = Read(fh, (char *)filebuff, filesize);
  1495.         Close(fh);
  1496.  
  1497.         if (actlength == -1L)
  1498.             return FALSE;
  1499.         else
  1500.             return TRUE;
  1501.     }
  1502.  
  1503.     return FALSE;
  1504. }
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510. /******************************************************************************
  1511. ** ErrorReq()
  1512. *******************************************************************************
  1513. ** input:   errornum    error number
  1514. ** output:  none
  1515. **
  1516. ** remarks: opens a requester and shows the error messages specified by
  1517. **          errornum
  1518. ******************************************************************************/
  1519.  
  1520. void ErrorReq(int errornum)
  1521. {
  1522.  
  1523.  
  1524.     set(app, MUIA_Application_Sleep, TRUE); /* deactivate the application */
  1525.  
  1526.  
  1527.     switch (errornum)
  1528.     {
  1529.         case  1:
  1530.             TxtRequest(AppStrings[MSG_ERR1].as_Str,
  1531.                        AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1532.             break;
  1533.  
  1534.         case  2:
  1535.             TxtRequest(AppStrings[MSG_ERR2].as_Str,
  1536.                        AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1537.             break;
  1538.  
  1539.         case  3:
  1540.             TxtRequest(AppStrings[MSG_ERR3].as_Str,
  1541.                        AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1542.             break;
  1543.  
  1544.         case  4:
  1545.             TxtRequest(AppStrings[MSG_ERR4].as_Str,
  1546.                        AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1547.             break;
  1548.  
  1549.         case  5:
  1550.             TxtRequest(AppStrings[MSG_ERR5].as_Str,
  1551.                        AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1552.             break;
  1553.  
  1554.         case  6:
  1555.             TxtRequest(AppStrings[MSG_ERR6].as_Str,
  1556.                        AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1557.             break;
  1558.  
  1559.         case  7:
  1560.             TxtRequest(AppStrings[MSG_ERR7].as_Str,
  1561.                        AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1562.             break;
  1563.  
  1564.         case  8:
  1565.             TxtRequest(AppStrings[MSG_ERR8].as_Str,
  1566.                        AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1567.             break;
  1568.  
  1569.         case  9:
  1570.             TxtRequest(AppStrings[MSG_ERR9].as_Str,
  1571.                        AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1572.             break;
  1573.  
  1574.         case 10:
  1575.             TxtRequest(AppStrings[MSG_ERR10].as_Str,
  1576.                        AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1577.             break;
  1578.  
  1579.         case 11:
  1580.             TxtRequest(AppStrings[MSG_ERR11].as_Str,
  1581.                        AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1582.             break;
  1583.  
  1584.         case 12:
  1585.             TxtRequest(AppStrings[MSG_ERR12].as_Str,
  1586.                        AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1587.             break;
  1588.  
  1589.         case 13:
  1590.             TxtRequest(AppStrings[MSG_ERR13].as_Str,
  1591.                        AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1592.             break;
  1593.     }
  1594.  
  1595.  
  1596.     set(app, MUIA_Application_Sleep, FALSE); /* reactivate the application */
  1597.  
  1598. }
  1599.  
  1600.  
  1601.  
  1602.  
  1603.  
  1604. /******************************************************************************
  1605. ** PrintText()
  1606. *******************************************************************************
  1607. ** input:   *text    pointer to text
  1608. **          newline  TRUE:  begin text in a new line
  1609. **                   FALSE: add this text to the last list entry
  1610. **
  1611. ** output:  none
  1612. **
  1613. ** remarks: prints text into text field
  1614. ******************************************************************************/
  1615.  
  1616. void PrintText(UBYTE *txt, int newline)
  1617. {
  1618.     #define LINE_LENGTH  100                 /* max. length of string */
  1619.  
  1620.  
  1621.     int     cntr, start_pos;
  1622.     char    line[LINE_LENGTH], *string;
  1623.  
  1624.     LONG    entries;
  1625.  
  1626.  
  1627.  
  1628.  
  1629.     get(LV_text, MUIA_List_Entries, &entries);   /* get number of entries */
  1630.  
  1631.     while (entries > MAX_NUM_OF_LINES)  /* if there are too many entries, */
  1632.     {                                   /* remove some                    */
  1633.  
  1634.         DoMethod(LV_text, MUIM_List_Remove, MUIV_List_Remove_First);
  1635.         entries--;
  1636.  
  1637.     }
  1638.  
  1639.  
  1640.     start_pos = 0;
  1641.  
  1642.     if (!newline && entries)
  1643.     {
  1644.  
  1645.                                                             /* get last entry */
  1646.         DoMethod(LV_text, MUIM_List_GetEntry, entries-1, &string);
  1647.  
  1648.                                                   /* does entry really exist? */
  1649.  
  1650.         if (string && (start_pos = strlen(string)))
  1651.         {
  1652.             strcpy(line, string);           /* copy list view entry into a  */
  1653.                                             /* buffer and remove this entry */
  1654.  
  1655.             DoMethod(LV_text, MUIM_List_Remove, entries-1);
  1656.         }
  1657.     }
  1658.  
  1659.  
  1660.  
  1661.     while (TRUE)
  1662.     {
  1663.         cntr = start_pos;                   /* search CR or end of */
  1664.         line[start_pos] = 0;                /* string              */
  1665.  
  1666.         while (*txt != 0x00 && *txt != 0x0A && cntr < LINE_LENGTH)
  1667.         {
  1668.             line[cntr++] = *txt++;             /* copy line into line-array */
  1669.         }
  1670.  
  1671.  
  1672.         line[cntr] = 0;                        /* set end of line */
  1673.  
  1674.  
  1675.         DoMethod(LV_text, MUIM_List_InsertSingle,  /* add line to  */
  1676.                  line, MUIV_List_Insert_Bottom);   /* the listview */
  1677.  
  1678.         if (!*txt)                             /* end of string reached? */
  1679.             break;
  1680.  
  1681.         txt++;
  1682.         start_pos = 0;                       /* begin new line at column 0 */
  1683.     }
  1684.  
  1685.                                              /* make last entry visible */
  1686.  
  1687.     DoMethod(LV_text, MUIM_List_Jump, MUIV_List_Jump_Bottom);
  1688.  
  1689. }
  1690.  
  1691.  
  1692.  
  1693.  
  1694.  
  1695. /******************************************************************************
  1696. ** PrintErrorLine()
  1697. *******************************************************************************
  1698. ** input:   line    line number to be printed
  1699. **
  1700. ** output:  none
  1701. **
  1702. ** remarks: prints error text with a line number
  1703. ******************************************************************************/
  1704.  
  1705. void PrintErrorLine(int line)
  1706. {
  1707.  
  1708.   sprintf((char *)&ErrorLineStr[16], "%4d:", line);
  1709.  
  1710.   PrintText(&ErrorLineStr[0],1);
  1711.  
  1712. }
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718. /******************************************************************************
  1719. ** LoadConfig()
  1720. *******************************************************************************
  1721. ** input:   none
  1722. ** output:  none
  1723. **
  1724. ** remarks: does load the configuration file "s:GALer.config"
  1725. ******************************************************************************/
  1726.  
  1727. void LoadConfig(void)
  1728. {
  1729.  
  1730.     LONG  filelength;
  1731.     BPTR  fh;
  1732.                                         /* get configuration file */
  1733.  
  1734.     if ((fh = Open((char *)"s:GALer.config", (long)MODE_OLDFILE)))
  1735.     {
  1736.         filelength = Read(fh, (char *)&DummyConfig,
  1737.                           (long)sizeof(struct Configuration));
  1738.         Close(fh);
  1739.  
  1740.         if (filelength == -1L)
  1741.             ErrorReq(10);
  1742.         else                            /* read error? */
  1743.             Config = DummyConfig;       /* then take the defaults */
  1744.     }
  1745.  
  1746.  
  1747.     GALType = UNKNOWN;
  1748.  
  1749.     SetGALType(Config.GALType);         /* set type of GAL */
  1750.  
  1751.     GALType = Config.GALType;
  1752.  
  1753.  
  1754.                                         /* GAL type requester */
  1755.     if (Config.GALTypeReq)
  1756.         DoMethod(main_win, MUIM_Window_SetMenuCheck, MEN_TYPEREQ, TRUE);
  1757.  
  1758.  
  1759.     hw_version = Config.HardwareVersion;        /* hardware version */
  1760.  
  1761.     switch (Config.HardwareVersion)
  1762.     {
  1763.         case HW_GALER_1_0:
  1764.             DoMethod(main_win, MUIM_Window_SetMenuCheck, MEN_VER11, TRUE);
  1765.             break;
  1766.  
  1767.         case HW_GALER_1_2:
  1768.             DoMethod(main_win, MUIM_Window_SetMenuCheck, MEN_VER12, TRUE);
  1769.             break;
  1770.  
  1771.         case HW_GALER_1_3:
  1772.             DoMethod(main_win, MUIM_Window_SetMenuCheck, MEN_VER13, TRUE);
  1773.             break;
  1774.  
  1775.         case HW_ELEKTOR_II:
  1776.             DoMethod(main_win, MUIM_Window_SetMenuCheck, MEN_VERELEKTOR, TRUE);
  1777.             DoMethod(main_win, MUIM_Window_SetMenuState, MEN_CALLCHECKER, FALSE);
  1778.             break;
  1779.     }
  1780.  
  1781.  
  1782.  
  1783.     if (hw_version <= HW_GALER_1_2)             /* enable/disable the 22V10 */
  1784.     {                                           /* and the 20RA10 menu      */
  1785.         DoMethod(main_win, MUIM_Window_SetMenuState, MEN_22V10,  FALSE);
  1786.         DoMethod(main_win, MUIM_Window_SetMenuState, MEN_20RA10, FALSE);
  1787.  
  1788.                                         /* hardware versions less or   */
  1789.                                         /* equal 1.2 do not support    */
  1790.                                         /* GAL22V10 and GAL20RA10 GALs */
  1791.         if (GALType == GAL22V10 || GALType == GAL20RA10)
  1792.             SetGALType(GAL16V8);
  1793.     }
  1794.     else
  1795.     {
  1796.         DoMethod(main_win, MUIM_Window_SetMenuState, MEN_22V10,  TRUE);
  1797.         DoMethod(main_win, MUIM_Window_SetMenuState, MEN_20RA10, TRUE);
  1798.     }
  1799.  
  1800. }
  1801.  
  1802.  
  1803.  
  1804.  
  1805.  
  1806. /******************************************************************************
  1807. ** SaveConfig()
  1808. *******************************************************************************
  1809. ** input:   none
  1810. ** output:  none
  1811. **
  1812. ** remarks: saves configuration to the file s:GALer.config
  1813. **
  1814. ******************************************************************************/
  1815.  
  1816. void SaveConfig(void)
  1817. {
  1818.     long  filelength;
  1819.     BPTR  fh;
  1820.  
  1821.  
  1822.  
  1823.     Config.GALType = GALType;
  1824.  
  1825.                                     /* save configuration file */
  1826.  
  1827.     if ((fh = Open((char *)"s:GALer.config", (long)MODE_NEWFILE)))
  1828.     {
  1829.         filelength = Write(fh, (char *)&Config,
  1830.                            (long)sizeof(struct Configuration));
  1831.  
  1832.         Close(fh);
  1833.  
  1834.         if (filelength == -1L)
  1835.             ErrorReq(11);           /* file does not exist */
  1836.     }
  1837.     else
  1838.     {
  1839.         ErrorReq(11);               /* file does not exist */
  1840.     }
  1841.  
  1842. }
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848. /******************************************************************************
  1849. ** SetGALType()
  1850. *******************************************************************************
  1851. ** input:   galtype   type of GAL
  1852. ** output:  none
  1853. **
  1854. ** remarks: This function does set all variables according to the new
  1855. **          type of GAL.
  1856. ******************************************************************************/
  1857.  
  1858. void SetGALType(int galtype)
  1859. {
  1860.  
  1861.     if (galtype == GAL16V8 && GALType != GAL16V8)
  1862.     {
  1863.         GALType    = GAL16V8;
  1864.         MaxFuseAdr = MAX_FUSE_ADR16;
  1865.         RowSize    = ROW_SIZE_16V8;
  1866.         XORSize    = 8;
  1867.         SigAdr     = SIG_ADR16;
  1868.  
  1869.         SetGAL(GAL16V8);
  1870.  
  1871.         SetSymbolGAL(GAL16V8);
  1872.  
  1873.         strncpy ((char *)&main_win_title[56], (char *)"GAL16V8  ", (size_t)9);
  1874.  
  1875.                                         /* set type menu to GAL16V8 */
  1876.         DoMethod(main_win, MUIM_Window_SetMenuCheck, MEN_16V8,   TRUE);
  1877.         DoMethod(main_win, MUIM_Window_SetMenuCheck, MEN_20V8,   FALSE);
  1878.         DoMethod(main_win, MUIM_Window_SetMenuCheck, MEN_22V10,  FALSE);
  1879.         DoMethod(main_win, MUIM_Window_SetMenuCheck, MEN_20RA10, FALSE);
  1880.     }
  1881.  
  1882.  
  1883.     if (galtype == GAL20V8 && GALType != GAL20V8)
  1884.     {
  1885.         GALType    = GAL20V8;
  1886.         MaxFuseAdr = MAX_FUSE_ADR20;
  1887.         RowSize    = ROW_SIZE_20V8;
  1888.         XORSize    = 8;
  1889.         SigAdr     = SIG_ADR20;
  1890.  
  1891.         SetGAL(GAL20V8);
  1892.  
  1893.         SetSymbolGAL(GAL20V8);
  1894.  
  1895.         strncpy ((char *)&main_win_title[56], (char *)"GAL20V8  ", (size_t)9);
  1896.  
  1897.                                         /* set type menu to GAL20V8 */
  1898.         DoMethod(main_win, MUIM_Window_SetMenuCheck, MEN_16V8,   FALSE);
  1899.         DoMethod(main_win, MUIM_Window_SetMenuCheck, MEN_20V8,   TRUE);
  1900.         DoMethod(main_win, MUIM_Window_SetMenuCheck, MEN_22V10,  FALSE);
  1901.         DoMethod(main_win, MUIM_Window_SetMenuCheck, MEN_20RA10, FALSE);
  1902.     }
  1903.  
  1904.  
  1905.     if (galtype == GAL22V10 && GALType != GAL22V10)
  1906.     {
  1907.         GALType    = GAL22V10;
  1908.         MaxFuseAdr = MAX_FUSE_ADR22V10;
  1909.         RowSize    = ROW_SIZE_22V10;
  1910.         XORSize    = 10;
  1911.         SigAdr     = SIG_ADR22V10;
  1912.  
  1913.         SetGAL(GAL22V10);
  1914.  
  1915.         SetSymbolGAL(GAL22V10);
  1916.  
  1917.         strncpy ((char *)&main_win_title[56], (char *)"GAL22V10 ", (size_t)9);
  1918.  
  1919.                                         /* set type menu to GAL22V10 */
  1920.         DoMethod(main_win, MUIM_Window_SetMenuCheck, MEN_16V8,   FALSE);
  1921.         DoMethod(main_win, MUIM_Window_SetMenuCheck, MEN_20V8,   FALSE);
  1922.         DoMethod(main_win, MUIM_Window_SetMenuCheck, MEN_22V10,  TRUE);
  1923.         DoMethod(main_win, MUIM_Window_SetMenuCheck, MEN_20RA10, FALSE);
  1924.     }
  1925.  
  1926.  
  1927.     if (galtype == GAL20RA10 && GALType != GAL20RA10)
  1928.     {
  1929.         GALType    = GAL20RA10;
  1930.         MaxFuseAdr = MAX_FUSE_ADR20RA10;
  1931.         RowSize    = ROW_SIZE_20RA10;
  1932.         XORSize    = 10;
  1933.         SigAdr     = SIG_ADR20RA10;
  1934.  
  1935.         SetGAL(GAL20RA10);
  1936.  
  1937.         SetSymbolGAL(GAL20RA10);
  1938.  
  1939.         strncpy ((char *)&main_win_title[56], (char *)"GAL20RA10", (size_t)9);
  1940.  
  1941.                                         /* set type menu to GAL20RA10 */
  1942.         DoMethod(main_win, MUIM_Window_SetMenuCheck, MEN_16V8,   FALSE);
  1943.         DoMethod(main_win, MUIM_Window_SetMenuCheck, MEN_20V8,   FALSE);
  1944.         DoMethod(main_win, MUIM_Window_SetMenuCheck, MEN_22V10,  FALSE);
  1945.         DoMethod(main_win, MUIM_Window_SetMenuCheck, MEN_20RA10, TRUE);
  1946.     }
  1947.  
  1948.  
  1949.     set(main_win, MUIA_Window_Title, main_win_title);
  1950. }
  1951.  
  1952.  
  1953.  
  1954.  
  1955.  
  1956. /* The functions AddByte(), AddString(), IncPointer(), DecPointer() */
  1957. /* and FreeBuffer() are useful for handling chained lists           */
  1958.  
  1959. /******************************************************************************
  1960. ** AddByte()
  1961. *******************************************************************************
  1962. ** input:   *buff   pointer to buffer structure
  1963. **          code    byte to add to the list
  1964. **
  1965. ** output:  0:   o.k.
  1966. *           !=0: error occured (e.g. not enough free memory)
  1967. **
  1968. ** remarks: This function does set a byte in a buffer. If the end of the buffer
  1969. **          is reached, a new buffer is added to the chained list of buffers.
  1970. **
  1971. ******************************************************************************/
  1972.  
  1973. int AddByte(struct ActBuffer *buff, UBYTE code)
  1974. {
  1975.     struct  Buffer  *mybuff;
  1976.  
  1977.  
  1978.     if ((buff->Entry) < (buff->BuffEnd))    /* is the current address within */
  1979.     {                                       /* the buffer ?                  */
  1980.         *buff->Entry++ = code;              /* the fill in the byte */
  1981.     }
  1982.     else
  1983.     {                                       /* if not, then add a new buffer */
  1984.         if (!(mybuff = (struct Buffer *)AllocMem((long)sizeof(struct Buffer),
  1985.                                                  MEMF_PUBLIC|MEMF_CLEAR)))
  1986.         {
  1987.             ErrorReq(2);
  1988.             return(-1);
  1989.         }
  1990.  
  1991.  
  1992.         buff->ThisBuff->Next = mybuff;      /* new buffer is current buffer */
  1993.         mybuff->Prev   = buff->ThisBuff;    /* previous is old buffer       */
  1994.         buff->ThisBuff = mybuff;            /* current buffer is new buffer */
  1995.         buff->Entry    = (UBYTE *)(&mybuff->Entries[0]);
  1996.         buff->BuffEnd  = (UBYTE *)mybuff + (long)sizeof(struct Buffer);
  1997.         *buff->Entry++ = code;
  1998.     }
  1999.  
  2000.  
  2001.     return(0);
  2002. }
  2003.  
  2004.  
  2005.  
  2006.  
  2007.  
  2008. /******************************************************************************
  2009. ** AddString()
  2010. *******************************************************************************
  2011. ** input:   *buff    pointer to buffer structure
  2012. **          strnptr  pointer to string to be added to the buffer
  2013. **
  2014. ** output:  0:   o.k.
  2015. *           !=0: error occured (e.g. not enough free memory)
  2016. **
  2017. ** remarks: This function does add a string to a buffer. If the end of the
  2018. **          buffer is reached, a new buffer is added to the chained list of
  2019. **          buffers.
  2020. **
  2021. ******************************************************************************/
  2022.  
  2023. int AddString(struct ActBuffer *buff, UBYTE *strnptr)
  2024. {
  2025.  
  2026.     while (*strnptr)
  2027.     {
  2028.         if (AddByte(buff, *strnptr++))
  2029.             return(-1);
  2030.     }
  2031.  
  2032.     return(0);
  2033. }
  2034.  
  2035.  
  2036.  
  2037.  
  2038.  
  2039. /******************************************************************************
  2040. ** IncPointer()
  2041. *******************************************************************************
  2042. ** input:   *buff   pointer to buffer structure
  2043. **
  2044. ** output:  none
  2045. **
  2046. ** remarks: This function does increment the pointer of the current buffer
  2047. **          structure. If the pointer points to the end of the buffer, the
  2048. **          pointer will be set to the beginning of the next entry of the
  2049. **          chained list.
  2050. **          ATTENTION: there is no test whether the absolut end of the chained
  2051. **                     list is reached or not!
  2052. **
  2053. ******************************************************************************/
  2054.  
  2055. void IncPointer(struct ActBuffer *buff)
  2056. {
  2057.  
  2058.     buff->Entry++;
  2059.  
  2060.     if (buff->Entry == buff->BuffEnd)       /* end of buffer reached? */
  2061.     {
  2062.         buff->ThisBuff = buff->ThisBuff->Next;  /* yes, then set the pointer */
  2063.                                                 /* to the next buffer        */
  2064.  
  2065.         buff->Entry    = (UBYTE *)(&buff->ThisBuff->Entries[0]);
  2066.  
  2067.         buff->BuffEnd  = (UBYTE *)buff->ThisBuff + (long)sizeof(struct Buffer);
  2068.     }
  2069.  
  2070. }
  2071.  
  2072.  
  2073.  
  2074.  
  2075.  
  2076. /******************************************************************************
  2077. ** DecPointer()
  2078. *******************************************************************************
  2079. ** input:   *buff   pointer to buffer structure
  2080. **
  2081. ** output:  none
  2082. **
  2083. ** remarks: This function does decrement the pointer of the current buffer
  2084. **          structure. If the pointer points to the start of the buffer, the
  2085. **          pointer will be set to the beginning of the previous entry of the
  2086. **          chained list.
  2087. **          ATTENTION: there is no test whether the absolut start of the chained
  2088. **                     list is reached or not!
  2089. **
  2090. ******************************************************************************/
  2091.  
  2092. void DecPointer(struct ActBuffer *buff)
  2093. {
  2094.  
  2095.     buff->Entry--;
  2096.  
  2097.     if (buff->Entry < &buff->ThisBuff->Entries[0])  /* start of buffer reached? */
  2098.     {
  2099.         buff->ThisBuff = buff->ThisBuff->Prev;    /* pointer to previous buffer */
  2100.  
  2101.         buff->BuffEnd  = (UBYTE *)buff->ThisBuff + (long)sizeof(struct Buffer);
  2102.  
  2103.         buff->Entry    = (UBYTE *)((buff->BuffEnd)-1L);
  2104.     }
  2105.  
  2106. }
  2107.  
  2108.  
  2109.  
  2110.  
  2111.  
  2112. /******************************************************************************
  2113. ** FreeBuffer()
  2114. *******************************************************************************
  2115. ** input:   *buff   pointer to buffer structure
  2116. **
  2117. ** output:  none
  2118. **
  2119. ** remarks: This function does free memory which is allocated by the chained
  2120. **          list.
  2121. **
  2122. ******************************************************************************/
  2123.  
  2124. void FreeBuffer(struct Buffer *buff)
  2125. {
  2126.     struct  Buffer  *nextbuff;
  2127.  
  2128.     do
  2129.     {
  2130.         nextbuff = buff->Next;
  2131.  
  2132.         FreeMem(buff, (long)sizeof(struct Buffer));
  2133.     }
  2134.     while (buff = nextbuff);
  2135.  
  2136. }
  2137.  
  2138.  
  2139.  
  2140.  
  2141.  
  2142. /******************************************************************************
  2143. ** SelectEditor()
  2144. *******************************************************************************
  2145. ** input:   none
  2146. ** output:  none
  2147. **
  2148. ** remarks: This function does open a window in which the editor
  2149. **          can be selected.
  2150. **
  2151. ******************************************************************************/
  2152.  
  2153. void SelectEditor(void)
  2154. {
  2155.  
  2156.     int    open, done;
  2157.  
  2158.     ULONG  id, signals;
  2159.  
  2160.     APTR   win;
  2161.     APTR   ok_gad, string_gad;
  2162.  
  2163.     STRPTR string;
  2164.  
  2165.  
  2166.  
  2167.  
  2168.     set(app, MUIA_Application_Sleep, TRUE);     /* deactivate application */
  2169.  
  2170.                                                 /* make window object */
  2171.     win = WindowObject,
  2172.         MUIA_Window_Title, AppStrings[MSG_SELEDITOR_WIN].as_Str,
  2173.         MUIA_Window_CloseGadget, FALSE,
  2174.         MUIA_Window_NoMenus, TRUE,
  2175.         MUIA_HelpNode, "MenEditor",
  2176.  
  2177.             WindowContents, VGroup,
  2178.                 Child, HGroup,
  2179.                     Child, Label2(AppStrings[MSG_EDITOR].as_Str),
  2180.                     Child, string_gad = String(Config.EditorStr, EDITOR_STR_SIZE),
  2181.                     End,
  2182.  
  2183.                 Child, HGroup,
  2184.                     Child, ok_gad = SimpleButton(AppStrings[MSG_OK_GAD].as_Str),
  2185.                     End,
  2186.                 End,
  2187.             End;
  2188.  
  2189.                                         /* set gadget IDs */
  2190.  
  2191.     DoMethod(string_gad, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  2192.              app, 2, MUIM_Application_ReturnID, EDITORSTRING_ID);
  2193.  
  2194.     DoMethod(ok_gad, MUIM_Notify, MUIA_Pressed, FALSE,
  2195.              app, 2, MUIM_Application_ReturnID, OK_GADID);
  2196.  
  2197.  
  2198.                                         /* init cycle chain */
  2199.  
  2200.     DoMethod(win, MUIM_Window_SetCycleChain, string_gad, ok_gad, NULL);
  2201.  
  2202.  
  2203.  
  2204.  
  2205.     if (win)                    /* window object created? */
  2206.     {
  2207.         DoMethod(app, OM_ADDMEMBER, win);       /* add win to application */
  2208.  
  2209.         set(win, MUIA_Window_Open, TRUE);       /* open window */
  2210.         get(win, MUIA_Window_Open, &open);
  2211.  
  2212.         if (open)                               /* is window opened? */
  2213.         {
  2214.  
  2215.             done = FALSE;
  2216.  
  2217.             while (!done)
  2218.             {
  2219.                 id = DoMethod(app, MUIM_Application_Input, &signals);
  2220.  
  2221.                 switch (id)
  2222.                 {
  2223.                     case OK_GADID:              /* copy string into buffer */
  2224.                     case EDITORSTRING_ID:
  2225.                         get(string_gad, MUIA_String_Contents, &string);
  2226.                         strcpy(Config.EditorStr, string);
  2227.                         done = TRUE;                        /* that's it */
  2228.                         break;
  2229.                 }
  2230.  
  2231.                 if (!done && signals)
  2232.                     Wait(signals);              /* wait for the next event */
  2233.             }
  2234.  
  2235.  
  2236.            set(win, MUIA_Window_Open, FALSE);   /* close window */
  2237.   
  2238.         }
  2239.  
  2240.         DoMethod(app, OM_REMMEMBER, win);       /* remove win from app. */
  2241.  
  2242.         MUI_DisposeObject(win);                 /* delete window object */
  2243.     }
  2244.  
  2245.  
  2246.  
  2247.     set(app, MUIA_Application_Sleep, FALSE);    /* reactivate application */
  2248.  
  2249. }
  2250.  
  2251.  
  2252.  
  2253.  
  2254.  
  2255. /******************************************************************************
  2256. ** CallEditor()
  2257. *******************************************************************************
  2258. ** input:   none
  2259. ** output:  none
  2260. **
  2261. ** remarks: Call editor and replace %s with the current *.pld-file.
  2262. **
  2263. ******************************************************************************/
  2264.  
  2265. void CallEditor(void)
  2266. {
  2267.     char  callstrn[100 + EDITOR_STR_SIZE];
  2268.     BPTR  ofh;
  2269.  
  2270.  
  2271.  
  2272.     set(app, MUIA_Application_Sleep, TRUE);     /* deactivate application */
  2273.  
  2274.  
  2275.     if (ofh = Open("NIL:", (long)MODE_NEWFILE))
  2276.     {                                           /* open file handle */
  2277.  
  2278.         if (strlen(prevSourceFile) <= 100)
  2279.         {                                       /* is string too long? */
  2280.  
  2281.             sprintf(&callstrn[0], Config.EditorStr, prevSourceFile);
  2282.  
  2283.             if (Execute(&callstrn[0], NULL, ofh) == FALSE)
  2284.                 TxtRequest(AppStrings[MSG_CALLED_ERR].as_Str,
  2285.                        AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  2286.  
  2287.         }
  2288.  
  2289.         Close(ofh);                             /* close output file handle */
  2290.  
  2291.     }
  2292.  
  2293.  
  2294.     set(app, MUIA_Application_Sleep, FALSE);    /* reactivate application */
  2295.  
  2296. }
  2297.  
  2298.  
  2299.  
  2300.  
  2301.  
  2302. /******************************************************************************
  2303. ** WaitForTimer()
  2304. *******************************************************************************
  2305. ** input:   micro:  time to wait in micro seconds
  2306. **
  2307. ** output:  none
  2308. **
  2309. ** remarks: does wait a time
  2310. ******************************************************************************/
  2311.  
  2312. void WaitForTimer(ULONG micro)
  2313. {
  2314.  
  2315.     timereq->tr_node.io_Command = TR_ADDREQUEST;
  2316.     timereq->tr_time.tv_secs    = 0;
  2317.     timereq->tr_time.tv_micro   = micro;
  2318.  
  2319.     DoIO((struct IORequest *)timereq);
  2320. }
  2321.  
  2322.  
  2323.  
  2324.  
  2325.  
  2326. /******************************************************************************
  2327. ** HelpOnHelp()
  2328. *******************************************************************************
  2329. ** input:   none
  2330. ** output:  none
  2331. **
  2332. ** remarks: does show how to get help on something
  2333. ******************************************************************************/
  2334.  
  2335. void HelpOnHelp(void)
  2336. {
  2337.  
  2338.     set(app, MUIA_Application_Sleep, TRUE);     /* deactivate application */
  2339.  
  2340.  
  2341.     TxtRequest(AppStrings[MSG_HELP_TXT].as_Str, AppStrings[MSG_OK_GAD].as_Str,
  2342.                                                                         NULL);
  2343.  
  2344.     set(app, MUIA_Application_Sleep, FALSE);    /* reactivate application */
  2345.  
  2346. }
  2347.  
  2348.  
  2349.  
  2350.  
  2351.  
  2352. /* EOF */
  2353.